#include<iostream>
using namespace std;
#include<vector>
int main() {
	int n1, n2;
	cin >> n1 >> n2;
	vector<int> arr1(n1), arr2(n2);
	for (int i = 0; i < n1; ++i)
		cin >> arr1[i];
	for (int i = 0; i < n2; ++i)
		cin >> arr2[i];
	int ans=0,sum;
	int l1 = 0, l2 = 0;
	while (l1 < n1 && l2 < n2) {
		sum =arr1[l1++] - arr2[l2++];
		while (sum != 0) {
			++ans;
			if (sum > 0)
				sum -= arr2[l2++];
			else
				sum += arr1[l1++];
		}
	}
	cout << ans;
}